package l1j.opqlo.NewSystem.Attack;

import static l1j.server.server.model.skill.L1SkillId.DOUBLE_BRAKE;
import static l1j.server.server.model.skill.L1SkillId.ENCHANT_VENOM;
import static l1j.server.server.model.skill.L1SkillId.FOE_SLAYER;
import static l1j.server.server.model.skill.L1SkillId.REDUCTION_ARMOR;
import static l1j.server.server.model.skill.L1SkillId.SHOCK_STUN;
import static l1j.server.server.model.skill.L1SkillId.SOUL_OF_FLAME;
import static l1j.server.server.model.skill.L1SkillId.SPECIAL_EFFECT_WEAKNESS_LV3;
import static l1j.server.server.model.skill.L1SkillId.STATUS_FREEZE;
import static l1j.server.server.model.skill.L1SkillId.ILLUSION_OGRE;
import static l1j.server.server.model.skill.L1SkillId.ILLUSION_AVATAR;
import static l1j.server.server.model.skill.L1SkillId.蒜頭雞湯;
import static l1j.server.server.model.skill.L1SkillId.烏骨雞湯;
import static l1j.server.server.model.skill.L1SkillId.CURSE_PARALYZE;




import java.util.ConcurrentModificationException;
import java.util.HashMap;

import l1j.opqlo.NewSystem.L1AttackCancel;
import l1j.opqlo.Timer.Controler.Server.ServerWarExecutor;
import l1j.server.server.ActionCodes;
import l1j.server.server.model.L1CastleLocation;
import l1j.server.server.model.L1Character;
import l1j.server.server.model.L1Chaser;
import l1j.server.server.model.L1Chaserl;
import l1j.server.server.model.L1WeaponSkill;
import l1j.server.server.model.Instance.L1ItemInstance;
import l1j.server.server.model.Instance.L1NpcInstance;
import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.model.Instance.L1PetInstance;
import l1j.server.server.model.Instance.L1SummonInstance;
import l1j.server.server.model.poison.L1DamagePoison;
import l1j.server.server.serverpackets.S_AttackMissPacket;
import l1j.server.server.serverpackets.S_AttackPacket;
import l1j.server.server.serverpackets.S_Paralysis;
import l1j.server.server.serverpackets.S_ServerMessage;
import l1j.server.server.serverpackets.S_SkillIconGFX;
import l1j.server.server.serverpackets.S_SkillSound;
import l1j.server.server.serverpackets.S_UseArrowSkill;
import l1j.server.server.templates.L1Skills;
import l1j.server.server.utils.Random;

//耐性 (>> 1: 除)  (<< 1: 乘)
public class L1AttackPc extends L1AttackModel {

	//	private static double[] _雙重破壞倍數 = { 1.5, 2.2, 2.4, 2.6, 2.8 };
	private static double[] _雙重破壞倍數 = {2.0 , 2.2, 2.4 , 2.8 , 3 };
	private static double[] _單雙手劍倍數 = { 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8,1.9, 2 };

	public L1AttackPc(final L1PcInstance attacker, final L1Character target) {
		if (target == null) {
			return;
		}

		if (target.isDead()) {
			return;
		}

		this._pc = attacker;

		if (target instanceof L1PcInstance) {
			this._targetPc = (L1PcInstance) target;
			this._calcType = PC_PC;

		} else if (target instanceof L1NpcInstance) {
			this._targetNpc = (L1NpcInstance) target;
			this._calcType = PC_NPC;
		}

		// 武器情報の取得
		this.weapon = this._pc.getWeapon();
		if (this.weapon != null) {
			this._weaponitem = this.weapon.getItem();
			this._weaponId = this._weaponitem.getItemId();
			this._weaponType = this._weaponitem.getType1();
			this._weaponType2 = this._weaponitem.getType();
			this._weaponAddHit = this._weaponitem.getHitModifier()
					+ this.weapon.getHitByMagic()
					+ this.weapon.getLvStatus().getLvHitModifier();
			this._weaponAddDmg = this._weaponitem.getDmgModifier()
					+ this.weapon.getDmgByMagic()
					+ this.weapon.getLvStatus().getLvDmgModifier();

			final int dmg = this.weapon.getLvStatus().getLvDmg();

			this._weaponSmall = this._weaponitem.getDmgSmall() + dmg;
			this._weaponLarge = this._weaponitem.getDmgLarge() + dmg;
			this._weaponRange = this._weaponitem.getRange();
			this._weaponBless = this._weaponitem.getBless();
			// TODO 魔法武器卷軸by missu0524
			// _weaponSkillType = weapon.getSkillType();
			// TODO 魔法武器卷軸by missu0524

			if (this._weaponType != 20 && this._weaponType != 62) {
				this._weaponEnchant = this.weapon.getEnchantLevel()
						- this.weapon.get_durability(); // 損傷分マイナス

			} else {
				this._weaponEnchant = this.weapon.getEnchantLevel();
			}

			this._weaponMaterial = this.weapon.getItem().getMaterial();
			if (this._weaponType == 20) {// 弓 武器類型:箭取回
				this._arrow = this._pc.getInventory().getArrow();
				if (this._arrow != null) {
					this._weaponBless = this._arrow.getItem().getBless();
					this._weaponMaterial = this._arrow.getItem().getMaterial();
				}
			}

			if (this._weaponType == 62) {// 鐵手甲 武器類型:飛刀取回
				this._sting = this._pc.getInventory().getSting();
				if (this._sting != null) {
					this._weaponBless = this._sting.getItem().getBless();
					this._weaponMaterial = this._sting.getItem().getMaterial();
				}
			}

			this._weaponDoubleDmgChance = this.weapon.getItem()
					.getDoubleDmgChance();
			this._weaponAttrEnchantKind = this.weapon.getAttrEnchantKind();
			this._weaponAttrEnchantLevel = this.weapon.getAttrEnchantLevel();
		}

		// ステータスによる追加ダメージ補正
		if (this._weaponType == 20) {// 弓 增加敏捷傷害
			final Integer dmg = L1AttackList.DEXD.get((int) this._pc.getDex());
			if (dmg != null) {
				this._statusDamage = dmg;
			}

		} else { // それ以外はＳＴＲ値参照abstract
			final Integer dmg = L1AttackList.STRD.get((int) this._pc.getStr());
			if (dmg != null) {
				this._statusDamage = dmg;
			}

		}

		this._target = target;
		this._targetId = target.getId();
		this._targetX = target.getX();
		this._targetY = target.getY();
	}

	/**
	 * 攻擊資訊送出
	 */
	@Override
	public final void action() {
		try {
			// TODO 補充海露拜和朱里安的箭矢圖檔by9001183ex
			if (this._pc == null) {
				return;
			}
			if (_target == null) {
				return;
			}
			// 改變面向
			_pc.setHeading(_pc.targetDirection(_targetX, _targetY));

			if (_weaponRange == -1) {// 遠距離武器
				longAction();

			} else {// 近距離武器
				shortAction();
			}
		}catch(final Exception e){}
	}

	/**
	 * 近距離攻擊封包發送
	 * */
	private void shortAction(){
		try {
			if (this._isHit) {
				this._pc.sendPacketsX10(new S_AttackPacket(this._pc,this._targetId, ActionCodes.ACTION_Attack));
				//			this._target.broadcastPacketExceptTargetSight(new S_DoActionGFX(this._targetId,ActionCodes.ACTION_Damage), this._pc);
			} else {
				if (this._targetId > 0) {
					this._pc.sendPacketsX10(new S_AttackMissPacket(this._pc,this._targetId));
				} else {
					this._pc.sendPacketsX10(new S_AttackPacket(this._pc, 0,ActionCodes.ACTION_Attack));
				}
			}
		}catch(final Exception e){}
	}
	/**
	 * 遠距離攻擊封包發送
	 * */
	private void longAction(){
		try {
			int arrowId = 2510;
			final L1ItemInstance weapon = this._pc.getWeapon();
			int _weaponType = 0;
			if (weapon != null) {
				_weaponType = weapon.getItem().getType1();
			}
			if (_weaponType == 20) {
				final L1ItemInstance arrow = this._pc.getInventory().getArrow();

				if (arrow != null) {
					if (arrow.getItemId() == 43001) {
						arrowId = 2349;
					} else {
						final int gfx = this._pc.getTempCharGfx();
						switch (gfx) {
						case 8719:
							arrowId = 8721;// TODO 柑橘
							break;

						case 8842:// TODO 海露拜 75、80等變身
						case 8900:
							arrowId = 8904;
							break;

						case 8845:// TODO 朱里安75、80等變身
						case 8913:
							arrowId = 8916;
							break;

						case 2445:
							arrowId = 8916;
							break; // TODO 瘋犬變身

						case 2446:
							arrowId = 8904;
							break;// TODO 狡狼變身

						case 2447:
							arrowId = 7972;
							break; // TODO 傲龍變身

						case 2448:
						case 2449:
							arrowId = 532;
							break;// TODO 朱凰、龍鳴變身

						default:// 其他
							arrowId = 66;
							break;
						}
					}
					this._pc.getInventory().removeItem(this._arrow, 1);

				} else if (weapon.getItemId() == 190) { // TODO 沒有箭矢，但是持有沙哈之弓
					arrowId = 2349;
				}
				this._pc.sendPacketsX10(new S_UseArrowSkill(this._pc,
						this._targetId, arrowId, this._targetX, this._targetY,
						this._isHit));
				//			if (this._isHit) {
				//				this._target.broadcastPacketExceptTargetSight(new S_DoActionGFX(this._targetId,ActionCodes.ACTION_Damage), this._pc);
				//			}
			} else if (_weaponType == 62) { // TODO 鐵手甲
				final L1ItemInstance _sting = this._pc.getInventory().getSting();
				;
				if (_sting != null) {
					this._pc.sendPacketsX10(new S_UseArrowSkill(this._pc,this._targetId, 2989, this._targetX, this._targetY,this._isHit));
					//				if (this._isHit) {
					//					this._target.broadcastPacketExceptTargetSight(new S_DoActionGFX(this._targetId,ActionCodes.ACTION_Damage), this._pc);
					//				}
					this._pc.getInventory().removeItem(_sting, 1);
				}
			}
		}catch(final Exception e){}
	}


	/**
	 * 底比斯武器魔法的效果
	 */
	@Override
	public void addChaserAttack() {
		int mr = 0;
		switch (this._calcType) {
		case PC_PC:
			mr = this._targetPc.getMr() - 2 * this._pc.getOriginalMagicHit();
			break;

		case PC_NPC:
			mr = this._targetNpc.getMr() - 2 * this._pc.getOriginalMagicHit();
			break;
		}

		double probability = 3 + this._pc.getTrueSp() * 0.25;
		probability -= mr / 10 * 0.1;

		switch (this._weaponId) {
		case 265:// 底比斯歐西裡斯雙刀
		case 266:// 底比斯歐西裡斯雙手劍
		case 267:// 底比斯歐西裡斯弓
		case 268:// 底比斯歐西裡斯魔杖
			if (probability / 1.1 > Random.nextInt(100) + 1) {
				final L1Chaser chaser = new L1Chaser(this._pc, this._target);
				chaser.begin();
			}
			break;
		}
	}

	/**
	 * バウンスアタックにより武器受到傷害 バウンスアタックの損傷確率は10%
	 */
	/*
	 * private void damagePcWeaponDurability() { if (this._calcType != PC_PC) {
	 * return; }
	 *
	 * if (this._weaponType == 0) { return; }
	 *
	 * if (this._weaponType == 20) { return; }
	 *
	 * if (this._weaponType == 62) { return; }
	 *
	 * /*if (this._targetPc.hasSkillEffect(BOUNCE_ATTACK) == false) { return; }
	 */
	/*
	 * if (this._pc.hasSkillEffect(SOUL_OF_FLAME)) { return; }
	 *
	 * if (Random.nextInt(100) + 1 <= 10) { // \f1你的%0%s壞了。
	 * this._pc.sendPackets(new S_ServerMessage(268, this.weapon.getLogName()));
	 * this._pc.getInventory().receiveDamage(this.weapon); } } /** 鎖鏈劍武器計算傷害公式實裝
	 * 鎖鏈劍攻撃魔法附加
	 */
	private final void addChaserlAttack() {

		if (5 >= Random.nextInt(100) + 1) {
			switch (this._weaponId) {
			case 272:
			case 273:
			case 318:
			case 319:
				// final L1Chaserl chaser =
				new L1Chaserl(this._pc, this._target, L1Skills.ATTR_EARTH, 6509)
				.begin();
				// chaser.begin();
				break;

			case 320:
				// final L1Chaserl chaser2 =
				new L1Chaserl(this._pc, this._target, L1Skills.ATTR_WATER, 6512)
				.begin();
				// chaser2.begin();
				break;
			}/*
			 * if (_weaponId == 272 || _weaponId == 273 || _weaponId == 318||
			 * _weaponId == 319) {
			 *
			 * final L1Chaserl chaser = new L1Chaserl(_pc, _target,
			 * L1Skills.ATTR_EARTH, 6509); chaser.begin(); } else if (_weaponId
			 * == 320) { final L1Chaserl chaser = new L1Chaserl(_pc, _target,
			 * L1Skills.ATTR_WATER, 6512); chaser.begin(); }
			 */
		}
	}

	/**
	 * PC附加毒性攻擊
	 *
	 * @param attacker
	 * @param target
	 */
	private void addPcPoisonAttack(final L1Character target) {
		// TODO 魔法娃娃DB化
		if (this._weaponId == 0) {
			return;
		}

		final int chance = Random.nextInt(100) + 1;
		if (chance <= 10) {
			int dmg = 0;
			int time = 3000;
			switch (this._weaponId) {

			case 13:
			case 44:
				dmg += 5;
				break;
				// opqlo
			case 582:
				dmg += 20;
				time = 1000;
				break;
			case 589:
				dmg += 30;
				time = 1000;
				break;
			case 596:
				dmg += 50;
				time = 1000;
				break;
			case 603:
				dmg += 100;
				time = 1000;
				break;
			case 610:
				dmg += 200;
				time = 1000;
				break;
			case 624:
				dmg += 250;
				time = 1000;
				break;
			case 631:
				dmg += 300;
				time = 1000;
				break;
			case 645:
				dmg += 350;
				time = 1000;
				break;
			case 653:
				dmg += 400;
				time = 1000;
				break;
			case 661:
			case 669:
			case 677:
				dmg += 400;
				time = 1000;
				break;

			}
			if (this._pc.hasSkillEffect(ENCHANT_VENOM)) {
				dmg += 5;
			}
			/** 怪怪的魔法娃娃功能 暫時移除 opqlo **/
			/*
			 * if (L1MagicDoll.getEffectByDoll(_pc, (byte) 1) == 1) { dmg += 5;
			 * }
			 */
			if (dmg != 0) {
				L1DamagePoison.doInfection(this._pc, target, time, dmg, true);
			}
		}
		/*
		 * if (((_weaponId == 13) || (_weaponId == 44 // FOD、古代のダークエルフソード ) ||
		 * ((_weaponId != 0) && _pc.hasSkillEffect(ENCHANT_VENOM))) // エンチャント //
		 * ベノム中 && (chance <= 10)) { //TODO 魔法娃娃DB化
		 *
		 * // 通常毒、3秒周期、ダメージHP-5 L1DamagePoison.doInfection(attacker, target,
		 * 3000, 5, true); //TODO 魔法娃娃DB化 } else { // TODO マジックドール效果 - 毒付与 if
		 * (L1MagicDoll.getEffectByDoll(attacker, (byte) 1) == 1) {
		 * L1DamagePoison.doInfection(attacker, target, 3000, 5, true); } }
		 */
	}

	// TODO 魔法娃娃DB化

	/*
	 * @Override public void addChaserAttack() { final L1Chaser chaser = new
	 * L1Chaser(_pc, _target); chaser.begin(); }
	 */
	/**
	 * 傷害計算
	 */
	@Override
	public int calcDamage() {
		switch (this._calcType) {
		case PC_PC:
			this._damage = this.calcPcDamage();
			break;

		case PC_NPC:
			this._damage = this.calcNpcDamage();
			break;
		}
		if(this._pc !=null){
			if(this._pc.hasSkillEffect(蒜頭雞湯)){
				this._damage *= 1.1;
			}
		}
		if(this._targetPc !=null){
			if(this._calcType == PC_PC){
				if(this._targetPc.hasSkillEffect(烏骨雞湯)){
					this._damage *= 0.9;
				}
			}
		}
		return this._damage;
	}

	@Override
	/* ■■■■■■■■■■■■■■■■ 命中判定 ■■■■■■■■■■■■■■■■ */
	public boolean calcHit() {
		if (L1AttackCancel.haveCancelSkill(this._target)) {
			this._isHit = false;
			return this._isHit;
		}
		if (this._calcType == PC_PC || this._calcType == PC_NPC) {
			if (this._weaponRange != -1) {
				if (this._pc.getLocation().getTileLineDistance(
						this._target.getLocation()) > this._weaponRange + 1) { // BIGのモンスターに対応するため射程範囲+1
					this._isHit = false; // 射程範囲外
					return this._isHit;
				}
			} else {
				if (!this._pc.getLocation().isInScreen(
						this._target.getLocation())) {
					this._isHit = false; // 射程範囲外
					return this._isHit;
				}
			}

			if (this._weaponType == 20 && this._weaponId != 190
					&& this._arrow == null) {
				this._isHit = false; // 矢がない場合はミス
			} else if (this._weaponType == 62 && this._sting == null) {
				this._isHit = false; // スティングがない場合はミス
			} else if (!this._pc.glanceCheck(this._targetX, this._targetY)) {
				this._isHit = false; // 攻撃者がプレイヤーの場合は障害物判定
			} else if (this._weaponId == 247 || this._weaponId == 248
					|| this._weaponId == 249) {
				this._isHit = false; // 試練の剣B～C 攻撃無効

			} else if (this._calcType == PC_NPC) {
				this._isHit = this.calcNpcHit();
			} else if (this._calcType == PC_PC) {
				this._isHit = this.calcPcHit();
			}
		}
		return this._isHit;
	}

	/**
	 * PC對NPC傷害
	 *
	 * @return
	 */
	private int calcNpcDamage() {
		if (this._targetNpc == null) {
			return 0;
		}

		// 傷害為0
		if (dmg0(this._targetNpc)) {
			this._isHit = false;
			return 0;
		}
		if (this.weapon == null) { // 素手
			return (Random.nextInt(5) + 4) / 4;
		}
		int weaponMaxDamage = 0;
		// if
		// (_targetNpc.getNpcTemplate().get_size().equalsIgnoreCase("small")&&
		// _weaponSmall > 0) {
		if (!this._targetNpc.isBigSize && this._weaponSmall > 0) {
			weaponMaxDamage = this._weaponSmall;
			// } else if
			// (_targetNpc.getNpcTemplate().get_size().equalsIgnoreCase("large")&&
			// _weaponLarge > 0) {
		} else if (this._targetNpc.isBigSize && this._weaponLarge > 0) {
			weaponMaxDamage = this._weaponLarge;
		}

		int weaponDamage = 0;
		if (this._weaponType == 58
				&& Random.nextInt(100) + 1 <= this._weaponDoubleDmgChance) { // クリティカルヒット
			weaponDamage = weaponMaxDamage;
			this._pc.sendPacketsX8(new S_SkillSound(this._pc.getId(), 3671));

		} else if (this._weaponType == 0 || this._weaponType == 20
				|| this._weaponType == 62) { // 素手、弓、ガントトレット
			weaponDamage = 0;
		} else {
			if (this._pc.hasSkillEffect(SOUL_OF_FLAME)) {
				weaponDamage = weaponMaxDamage;
			} else {
				weaponDamage = Random.nextInt(weaponMaxDamage) + 1;
			}
		}

		int weaponTotalDamage = weaponDamage + this._weaponAddDmg
				+ this._weaponEnchant + this.calcMaterialBlessDmg(); // 銀祝福ダメージボーナス
		if (this._weaponType == 54 || this._weaponType == 58) {
			if (this._weaponType == 54
					&& Random.nextInt(100) + 1 <= this._weaponDoubleDmgChance) { // ダブルヒット
				weaponDamage = weaponMaxDamage;
				this._pc.sendPacketsX8(new S_SkillSound(this._pc.getId(), 3398));
			}
			if (this._pc.hasSkillEffect(DOUBLE_BRAKE)
					&& Random.nextInt(100) + 1 <= 25) {
				weaponTotalDamage *=  _雙重破壞倍數[Random.nextInt(_雙重破壞倍數.length)];
			}
		} else if (this._weaponType == 4 || this._weaponType == 50) {
			if (Random.nextInt(100) + 1 <= 50) {

				weaponTotalDamage *= _單雙手劍倍數[Random.nextInt(_單雙手劍倍數.length)];
			}
		}

		final int ac = Math.max(0, this._targetNpc.getAc() * -1);
		final int defac = Random.nextInt(ac);
		double dmg = 0;
		if(_pc.hasSkillEffect(ILLUSION_OGRE)){ //幻術士魔法 (幻覺歐吉) 
			dmg += 4;
		}
		if(_pc.hasSkillEffect(ILLUSION_AVATAR)){//幻術士魔法 (幻覺：化身)
			dmg += 10;
		}
		if (this._weaponType != 20 && this._weaponType != 62) {
			dmg += Math.max(0,
					weaponTotalDamage + this._statusDamage
					+ this._pc.getDmgup() + this._pc.getOriginalDmgup()
					+ this._pc.getDmgModifierByArmor()
					+ this._pc.getDollList().getDmg()
					- defac);// TODO 魔法娃娃DB化

			if (dmg == 0) {
				this._isHit = false;
				return 0;
			}
			dmg += this.dmgUp();

			/*
			 * if (_weaponId == 262 && Random.nextInt(100) + 1 <= 75) { // 毀滅巨劍
			 * 装備かつ成功確率(暫定)75% weaponTotalDamage +=
			 * calcDestruction(weaponTotalDamage); }
			 */
			if (this._weaponType == 24) {
				// 弱點曝光發動判斷
				this.WeaknessExposure();
				// 弱點曝光 LV3 時，使用屠宰者加成 30% 傷害，弱點消失
				if (this._pc.hasSkillEffect(FOE_SLAYER)
						&& this._pc.hasSkillEffect(SPECIAL_EFFECT_WEAKNESS_LV3)) {
					dmg *= 2;
					this._pc.killSkillEffectTimer(SPECIAL_EFFECT_WEAKNESS_LV3);
					this._pc.sendPackets(new S_SkillIconGFX(75, 0));
				}
			} else if (this._weaponType2 == 17) { // キーリンク
				dmg += L1WeaponSkill.getKiringkuDamage(this._pc, this._target);
				// dmg += calcAttrEnchantDmg(dmg);
			}
			/*
			 * if (_pc.hasSkillEffect(COOKING_2_0_N) // 料理による追加ダメージ ||
			 * _pc.hasSkillEffect(COOKING_2_0_S) ||
			 * _pc.hasSkillEffect(COOKING_3_2_N) ||
			 * _pc.hasSkillEffect(COOKING_3_2_S)) { dmg += 1; }
			 */
		} else {
			dmg += Math.max(
					0,
					weaponTotalDamage + this._statusDamage
					+ this._pc.getBowDmgup()
					+ this._pc.getOriginalBowDmgup()
					+ this._pc.getBowDmgModifierByArmor() - defac);

			if (this._weaponType == 20) { // 弓
				if (this._arrow != null) {
					int add_dmg = 0;
					// if
					// (_targetNpc.getNpcTemplate().get_size().equalsIgnoreCase("large"))
					// {
					if (this._targetNpc.isBigSize) {
						add_dmg = this._arrow.getItem().getDmgLarge();
					} else {
						add_dmg = this._arrow.getItem().getDmgSmall();
					}
					if (add_dmg == 0) {
						add_dmg = 1;
					}
					/*
					 * if (_targetNpc.getNpcTemplate().is_hard()) {//OPQLO 硬皮怪
					 * add_dmg /= 2; }
					 */
					dmg = dmg + Random.nextInt(add_dmg) + 1;

					if(this._arrow.getItemId() == 610028){//束縛之箭
						this.freeze_arrow();
					}
				} else if (this._weaponId == 190) { // サイハの弓
					dmg = dmg + Random.nextInt(15) + 1;
				}
			} else if (this._weaponType == 62) { // ガントトレット
				int add_dmg = 0;
				// if
				// (_targetNpc.getNpcTemplate().get_size().equalsIgnoreCase("large"))
				// {
				if (this._targetNpc.isBigSize) {
					add_dmg = this._sting.getItem().getDmgLarge();
				} else {
					add_dmg = this._sting.getItem().getDmgSmall();
				}
				if (add_dmg == 0) {
					add_dmg = 1;
				}
				dmg = dmg + Random.nextInt(add_dmg) + 1;
			}
			/*
			 * if (_pc.hasSkillEffect(COOKING_2_3_N) // 料理による追加ダメージ ||
			 * _pc.hasSkillEffect(COOKING_2_3_S) ||
			 * _pc.hasSkillEffect(COOKING_3_0_N) ||
			 * _pc.hasSkillEffect(COOKING_3_0_S)) { dmg += 1; }
			 */
		}
		if (dmg == 0) {
			this._isHit = false;
			return 0;
		}

		dmg = this.calcBuffDamage(dmg);
		dmg *= this.getWeakNess(); // 弱點曝光
		dmg += L1WeaponSkill.getWeaponSkillDamage(this._pc, this._targetNpc,
				this._weaponId);
		dmg *= 1 + this.getSpAttack();// 種族相剋
		dmg = this.calcAttrEnchantDmg(dmg); // 属性強化 opqlo 屬性相剋改寫
		this.addPcPoisonAttack(this._targetNpc);
		this.addChaserlAttack();

		/*
		 * if (_weaponId == 124) { // 巴風特魔杖 dmg +=
		 * L1WeaponSkill.getBaphometStaffDamage(_pc, _target); } else if
		 * (_weaponId == 204 || _weaponId == 100204) { // 深紅之弩
		 * L1WeaponSkill.giveFettersEffect(_pc, _targetNpc); } else if
		 * (_weaponId == 264) { // 雷雨之劍 dmg +=
		 * L1WeaponSkill.getLightningEdgeDamage(_pc, _target); } else if
		 * (_weaponId == 260 || _weaponId == 263) { // 狂風之斧 dmg +=
		 * L1WeaponSkill.getAreaSkillWeaponDamage(_pc, _target,_weaponId); }
		 * else if (_weaponId == 261) { // 大法師魔仗
		 * L1WeaponSkill.giveArkMageDiseaseEffect(_pc, _target); } else { dmg +=
		 * L1WeaponSkill.getWeaponSkillDamage(_pc, _target, _weaponId); }
		 */

		/********* 幽能攻擊公式(直接傷害) *********/
		// opqlo 額外攻擊力
		dmg += this._pc.getExtraDmg();
		// opqlo 額外攻擊力

		/********************* 攻擊力減少公式 *************************/

		dmg -= this.calcPcDefense();// 被攻擊者防禦力傷害直減低
		dmg -= this.calcNpcDamageReduction(); // opqlo 怪物減傷公式

		final int DmgReduce = this._targetNpc.getDmgReduceRate();
		if (DmgReduce >= 100) {
			dmg = 1;

		} else if (DmgReduce > 0) { // opqlo 怪物減傷倍率
			dmg = Math.max(dmg / DmgReduce, 1);
		}

		if (this._weaponType == 20
				&& this._targetNpc.getNpcTemplate().is_hard()) { // opqlo 硬皮怪
			dmg = Math.max(dmg / 2, 1);

		}

		if (dmg <= 0) {
			this._isHit = false;
			this._drainHp = 0; // ダメージ無しの場合は吸収による回復はしない
		}

//		if (this._pc.hasSkillEffect(戰鬥月餅) && Random.nextInt(100) + 1 < 10) {
//			dmg = this._targetNpc.getMaxHp();
//		}

		// プレイヤーからペット、サモンに攻撃
		boolean isNowWar = false;
		final int castleId = L1CastleLocation
				.getCastleIdByArea(this._targetNpc);
		if (castleId > 0) {
			isNowWar = ServerWarExecutor.get().isNowWar(castleId);
		}
		if (!isNowWar) {
			if (this._targetNpc instanceof L1PetInstance) {
				dmg = (int) dmg >> 10;
			} else if (this._targetNpc instanceof L1SummonInstance) {
				final L1SummonInstance summon = (L1SummonInstance) this._targetNpc;
				if (summon.isExsistMaster()) {
					// dmg /= 8;
					dmg = (int) dmg >> 10;
				}
			}
		}

		return (int) dmg;
	}

	/**
	 * PC對NPC的命中
	 *
	 * @return
	 */
	private boolean calcNpcHit() {
		// 對不可見的怪物額外判斷
		final int gfxid = this._targetNpc.getNpcTemplate().get_gfxid();
		switch (gfxid) {
		case 2412:// 南瓜的影子
			if (!this._pc.getInventory().checkEquipped(20046)) {// 南瓜帽
				return false;
			}
			break;
		}

		// 傷害為0
		if (dmg0(this._targetNpc)) {
			return false;
		}

		if (this._weaponType2 == 17) {// 奇古獸 命中100%
			return true;
		}

		// ＮＰＣへの命中率
		// ＝（PCのLv＋クラス補正＋STR補正＋DEX補正＋武器補正＋DAIの枚数/2＋魔法補正）×5−{NPCのAC×（-5）}
		this._hitRate = this._pc.getLevel();

		// 力量命中補正 / 敏捷命中補正
		this._hitRate += this.str_dex_Hit();
		if(_pc.hasSkillEffect(ILLUSION_OGRE)){ //幻術士魔法 (幻覺歐吉) 
			this._hitRate += 4;
		}
		if (this._weaponType != 20 && this._weaponType != 62) {
			this._hitRate +=
					// (this._weaponAddHit + this._pc.getHitup() +
					// this._pc.getOriginalHitup() + (this._weaponEnchant / 2)); // XXX
					this._weaponAddHit + this._pc.getHitup()
					+ this._pc.getOriginalHitup() + this._weaponEnchant * 0.6;

		} else {
			this._hitRate +=
					// (this._weaponAddHit + this._pc.getBowHitup() +
					// this._pc.getOriginalBowHitup() + (this._weaponEnchant / 2));//
					// XXX
					this._weaponAddHit + this._pc.getBowHitup()
					+ this._pc.getOriginalBowHitup() + this._weaponEnchant
					* 0.6;
		}

		if (this._weaponType != 20 && this._weaponType != 62) { // 防具による追加命中
			this._hitRate += this._pc.getHitModifierByArmor();

		} else {
			this._hitRate += this._pc.getBowHitModifierByArmor();
		}

		final int weight240 = this._pc.getInventory().getWeight240();
		if (weight240 > 80) { // 重量による命中補正
			if (80 < weight240 && 120 >= weight240) {
				this._hitRate -= 1;

			} else if (121 <= weight240 && 160 >= weight240) {
				this._hitRate -= 3;

			} else if (161 <= weight240 && 200 >= weight240) {
				this._hitRate -= 5;
			}
		}

		// _hitRate += hitUp();

		// int attackerDice = _random.nextInt(20) + 1 + this._hitRate - 10;//
		// TEST
		int attackerDice = Random.nextInt(20) + 2 + this._hitRate - 10;

		// 技能增加閃避
		attackerDice += attackerDice(this._targetNpc);

		final int defenderDice = 10 - this._targetNpc.getAc();

		final int fumble = this._hitRate - 9;
		final int critical = this._hitRate + 10;
		if (this._pc.isDragonKnight()) {
			attackerDice *= 1.01;
		}
		if (this._pc.isElf()) {
			if (this._pc.getElfAttr() == 2) {
				attackerDice *= 1.02;
			}
		}

		if (attackerDice <= fumble) {
			this._hitRate = 15;

		} else if (attackerDice >= critical) {
			this._hitRate = 100;

		} else {
			if (attackerDice > defenderDice) {
				this._hitRate = 100;

			} else if (attackerDice <= defenderDice) {
				this._hitRate = 15;
			}
		}

		final int npcId = this._targetNpc.getNpcTemplate().get_npcId();

		final Integer tgskill = L1AttackList.SKNPC.get(npcId);
		if (tgskill != null) {
			if (!this._pc.hasSkillEffect(tgskill)) {
				this._hitRate = 0;
			}
		}

		final Integer tgpoly = L1AttackList.PLNPC.get(npcId);
		if (tgpoly != null) {
			if (tgpoly.equals(this._pc.getTempCharGfx())) {
				this._hitRate = 0;
			}
		}

		final int rnd = Random.nextInt(100) + 1;

		return this._hitRate >= rnd;
	}

	/**
	 * PC對PC傷害計算
	 */
	private int calcPcDamage() {

		if (this._targetPc == null) {
			return 0;
		}
		// 傷害為0
		if (dmg0(this._targetPc)) {
			this._isHit = false;
			return 0;
		}
		if (!this._isHit) {
			return 0;
		}

		if (this.weapon == null) { // 素手
			return (Random.nextInt(5) + 4) / 4;
		}
		final int weaponMaxDamage = this._weaponSmall;
		int weaponDamage = 0;

		if (this._weaponType == 58
				&& Random.nextInt(100) + 1 <= this._weaponDoubleDmgChance) { // クリティカルヒット
			weaponDamage = weaponMaxDamage;
			this._pc.sendPacketsX8(new S_SkillSound(this._pc.getId(), 3671));
		} else 	if (this._weaponType == 54
				&& Random.nextInt(100) + 1 <= this._weaponDoubleDmgChance) { // ダブルヒット
			weaponDamage = weaponMaxDamage;
			this._pc.sendPacketsX8(new S_SkillSound(this._pc.getId(), 3398));
		} else if (this._weaponType == 0 || this._weaponType == 20
				|| this._weaponType == 62) { // 素手、弓、ガントトレット
			weaponDamage = 0;
		} else {
			if (this._pc.hasSkillEffect(SOUL_OF_FLAME)) {
				weaponDamage = weaponMaxDamage;
			} else {
				weaponDamage = Random.nextInt(weaponMaxDamage) + 1;
			}
		}
		int weaponTotalDamage = weaponDamage + this._weaponAddDmg+ this._weaponEnchant;

		if (this._weaponType == 54 || this._weaponType == 58) {
			if (this._pc.hasSkillEffect(DOUBLE_BRAKE)
					&& Random.nextInt(100) + 1 <= 25) {
				weaponTotalDamage -= this._weaponEnchant;
				weaponTotalDamage *=  _雙重破壞倍數[Random.nextInt(_雙重破壞倍數.length)];
				weaponTotalDamage += (this._weaponEnchant *2);
			}
		} else if (this._weaponType == 4 || this._weaponType == 50) {
			if (Random.nextInt(100) + 1 <= 15) {
				weaponTotalDamage *= _單雙手劍倍數[Random.nextInt(_單雙手劍倍數.length)];
			}
		} else if (this._weaponType == 24) {// TODO 鎖鏈劍
			weaponTotalDamage *= this.getWeakNess();// 弱點曝光
		}

		/*
		 * else if(_weaponType == 50){ if (Random.nextInt(100) + 1 <= 30)
		 * weaponTotalDamage *= 1.3; }
		 */

		if (this._weaponAttrEnchantLevel > 0) {
			weaponTotalDamage += this.calcAttrEnchantDmg(1); // 属性強化ダメージボーナス
		}

		/*
		 * if (_weaponId == 262 && Random.nextInt(100) + 1 <= 75) { //
		 * 毀滅巨劍成功確率(暫定)75% weaponTotalDamage +=
		 * calcDestruction(weaponTotalDamage); }
		 */
		double dmg =0;
		if(_pc.hasSkillEffect(ILLUSION_OGRE)){ //幻術士魔法 (幻覺歐吉) 
			dmg += 4;
		}
		if(_pc.hasSkillEffect(ILLUSION_AVATAR)){//幻術士魔法 (幻覺：化身)
			dmg += 10;
		}
		if (this._weaponType != 20 && this._weaponType != 62) {

			dmg += weaponTotalDamage + this._statusDamage + this._pc.getDmgup()
					+ this._pc.getOriginalDmgup()
					+ this._pc.getDmgModifierByArmor()
					+ this._pc.getDollList().getDmg(); // 防具による追加ダメージ
			if (this._weaponType2 == 17) { // キーリンク
				dmg += L1WeaponSkill
						.getKiringkuDamage(this._pc, this._targetPc);

			} else if (this._weaponType == 24) {// TODO 鎖鏈劍
				// TODO 弱點曝光發動判斷
				this.WeaknessExposure();
				// TODO 弱點曝光 LV3 時，使用屠宰者加成 30% 傷害，弱點消失
				if (this._pc.hasSkillEffect(FOE_SLAYER)
						&& this._pc.hasSkillEffect(SPECIAL_EFFECT_WEAKNESS_LV3)) {
					dmg *= 2;
					this._pc.killSkillEffectTimer(SPECIAL_EFFECT_WEAKNESS_LV3);
					this._pc.sendPackets(new S_SkillIconGFX(75, 0));
				}
			}/*
			 * if (_pc.hasSkillEffect(COOKING_2_0_N) // 料理による追加ダメージ ||
			 * _pc.hasSkillEffect(COOKING_2_0_S) ||
			 * _pc.hasSkillEffect(COOKING_3_2_N) ||
			 * _pc.hasSkillEffect(COOKING_3_2_S)) { dmg += 1; }
			 */
		} else {
			dmg += weaponTotalDamage + this._statusDamage
					+ this._pc.getBowDmgup() + this._pc.getOriginalBowDmgup()
					+ this._pc.getBowDmgModifierByArmor(); // 防具による追加ダメージ

			if (this._weaponType == 20) { // 弓
				if (this._arrow != null) {
					int add_dmg = this._arrow.getItem().getDmgSmall();
					if (add_dmg == 0) {
						add_dmg = 1;
					}
					dmg += Random.nextInt(add_dmg) + 1;
					if(this._arrow.getItemId() == 610028){//束縛之箭
						this.freeze_arrow();
					}
				} else if (this._weaponId == 190) { // サイハの弓
					dmg = dmg + Random.nextInt(15) + 1;
				}
			} else if (this._weaponType == 62) { // ガントトレット
				int add_dmg = this._sting.getItem().getDmgSmall();
				if (add_dmg == 0) {
					add_dmg = 1;
				}
				dmg += Random.nextInt(add_dmg) + 1;
			}
		}

		dmg += this.dmgUp();
		dmg = this.calcBuffDamage(dmg);
		dmg += L1WeaponSkill.getWeaponSkillDamage(this._pc, this._target,this._weaponId);
		this.addPcPoisonAttack(this._targetPc);
		this.addChaserlAttack();
		dmg *= 1 + this.getSpAttack();
		dmg += this._pc.getExtraDmg();

		/********************* 攻擊力減少公式 *************************/
		/** 娃娃增加減傷opqlo改寫 **/
		dmg -= this._targetPc.getDamageReductionByArmor()
				+ this._targetPc.getDollList().getDamageReduction(); // 減傷

		if (this._targetPc.hasSkillEffect(REDUCTION_ARMOR)) {
			final int targetPcLvl = this._targetPc.getLevel() - 50;

			dmg -= Math.max(targetPcLvl, 0) / 5 + 1;
		}

		boolean dmgX2 = false;// 傷害除2
		// 取回技能
		if (!this._targetPc.getSkillisEmpty()
				&& this._targetPc.getSkillEffect().size() > 0) {
			try {
				for (final Integer key : this._targetPc.getSkillEffect()) {
					final Integer integer = L1AttackList.SKD3.get(key);
					if (integer != null) {
						if (integer.equals(key)) {
							dmgX2 = true;
						} else {
							dmg += integer;
						}
					}
				}
			} catch (final ConcurrentModificationException e) {
				// 技能取回發生其他線程進行修改
			} catch (final Exception e) {
				// _log.error(e.getLocalizedMessage(), e);
			}
		}
		if (dmgX2) {
			dmg /= 2;
		}
		// }

		if (dmg <= 0) {
			this._isHit = false;
			this._drainHp = 0; // ダメージ無しの場合は吸収による回復はしない
		}

		return (int) dmg;
	}

	/**
	 * PC對PC的命中
	 *
	 * @return
	 */
	private boolean calcPcHit() {
		if (this._targetPc == null) {
			return false;
		}

		// 傷害為0
		if (dmg0(this._targetPc)) {
			return false;
		}

		/*
		 * // 迴避攻擊 if (calcEvasion()) { return false; }
		 */

		if (this._weaponType2 == 17) {// 奇古獸
			return true;
		}

		this._hitRate = this._pc.getLevel();
		this._hitRate += this._pc.getClassFeature().getHitLevel(this._pc.getLevel());// 職業物理命中補正

		// 力量命中補正 / 敏捷命中補正
		this._hitRate += this.str_dex_Hit();
		if(_pc.hasSkillEffect(ILLUSION_OGRE)){ //幻術士魔法 (幻覺歐吉) 
			this._hitRate += 4;
		}
		if (this._weaponType != 20 && this._weaponType != 62) {
			this._hitRate +=
					// (this._weaponAddHit + this._pc.getHitup() +
					// this._pc.getOriginalHitup() + (this._weaponEnchant / 2));// TEST
					this._weaponAddHit + this._pc.getHitup()
					+ this._pc.getOriginalHitup() + this._weaponEnchant * 0.6;

		} else {
			this._hitRate +=
					// (this._weaponAddHit + this._pc.getBowHitup() +
					// this._pc.getOriginalBowHitup() + (this._weaponEnchant / 2));//
					// TEST
					this._weaponAddHit + this._pc.getBowHitup()
					+ this._pc.getOriginalBowHitup() + this._weaponEnchant
					* 0.6;
		}

		if (this._weaponType != 20 && this._weaponType != 62) { // 防具による追加命中
			this._hitRate += this._pc.getHitModifierByArmor();

		} else {
			this._hitRate += this._pc.getBowHitModifierByArmor();
		}

		final int weight240 = this._pc.getInventory().getWeight240();
		if (weight240 > 80) { // 重量による命中補正
			if (80 < weight240 && 120 >= weight240) {
				this._hitRate -= 1;

			} else if (121 <= weight240 && 160 >= weight240) {
				this._hitRate -= 3;

			} else if (161 <= weight240 && 200 >= weight240) {
				this._hitRate -= 5;
			}
		}

		// _hitRate += hitUp();

		// int attackerDice = _random.nextInt(20) + 1 + this._hitRate - 10;//
		// TEST
		int attackerDice = Random.nextInt(20) + 2 + this._hitRate - 10;

		// 技能增加閃避
		attackerDice += attackerDice(this._targetPc);

		int defenderDice = 0;

		final int defenderValue = (int) (this._targetPc.getAc() * 1.5) * -1;

		if (this._targetPc.getAc() >= 0) {
			defenderDice = 10 - this._targetPc.getAc();

		} else if (this._targetPc.getAc() < 0) {
			defenderDice = 10 + Random.nextInt(defenderValue) + 1;
		}

		final int fumble = this._hitRate - 9;
		final int critical = this._hitRate + 10;
		if (this._pc.isDragonKnight()) {
			attackerDice *= 1.01;
		}
		if (this._pc.isElf()) {
			if (this._pc.getElfAttr() == 2) {
				attackerDice *= 1.02;
			}
		}

		if (attackerDice <= fumble) {
			this._hitRate = 15;

		} else if (attackerDice >= critical) {
			this._hitRate = 100;

		} else {
			if (attackerDice > defenderDice) {
				this._hitRate = 100;

			} else if (attackerDice <= defenderDice) {
				this._hitRate = 15;
			}
		}

		final int rnd = Random.nextInt(100) + 1;
		if (this._weaponType == 20) {// 弓 附加ER計算
			if (this._hitRate > rnd) {
				return this.calcErEvasion();
			}
		}
		return this._hitRate >= rnd;
	}

	/**
	 * 魔力奪取武器 MP奪取質計算
	 */
	@Override
	public void calcStaffOfMana() {
		switch (this._weaponId) {
		case 126: // 瑪那魔杖
		case 127: // 鋼鐵瑪那魔杖
		case 581:
		case 588:
		case 595:
		case 602:
		case 609:
		case 616:
		case 623:
		case 652:
		case 660:

			int som_lvl = this._weaponEnchant + 3; // 最大MP吸収量を設定
			if (som_lvl < 0) {
				som_lvl = 0;
			}
			// MP修收量取得(最大吸收9)
			this._drainMana = Math.min(Random.nextInt(som_lvl)+1, 9);
			break;

		case 259: // 魔力短劍
			switch (this._calcType) {
			case PC_PC:
				if (this._targetPc.getMr() <= Random.nextInt(100) + 1) { // 確率はターゲットのMRに依存
					this._drainMana = 1; // 吸収量は1固定
				}
				break;

			case PC_NPC:
				if (this._targetNpc.getMr() <= Random.nextInt(100) + 1) { // 確率はターゲットのMRに依存
					this._drainMana = 1; // 吸収量は1固定
				}
				break;
			}
			break;
		}
	}

	@Override
	public void commit() {
		// ●●●● プレイヤーに計算結果を反映 ●●●●
		if (!this._isHit) {
			return;
		}
		if (this._calcType == PC_PC) {
			if (this._drainMana > 0 ) {
				if(this._targetPc.getCurrentMp() > 0){
					this._drainMana = Math.min(this._drainMana,this._targetPc.getCurrentMp());
					final int newMp =this._targetPc.getCurrentMp() - this._drainMana;
					this._targetPc.setCurrentMp(newMp);
					final int newMp2 = this._pc.getCurrentMp() + this._drainMana;
					this._pc.setCurrentMp(newMp2);
				}
			}
			if (this._drainHp > 0) { // HP吸収による回復
				final short newHp = (short) (this._pc.getCurrentHp() + this._drainHp);
				this._pc.setCurrentHp(newHp);
			}
			// damagePcWeaponDurability(); // 武器を損傷させる。
			this._targetPc.receiveDamage(this._pc, this._damage, false);
			if (!this._pc.isGm()) {
				if (!this._targetPc.isGm()) {
					return;
				}
			}
		} else if (this._calcType == PC_NPC) {
			if (this._drainMana > 0) {
				final int drainValue = this._targetNpc.drainMana(this._drainMana);
				final int newMp = this._pc.getCurrentMp() + drainValue;
				this._pc.setCurrentMp(newMp);
				if (drainValue > 0) {
					final int newMp2 = this._targetNpc.getCurrentMp()- drainValue;
					this._targetNpc.setCurrentMpDirect(newMp2);
				}
			}
			if (this._drainHp > 0) { // HP吸収による回復
				final short newHp = (short) (this._pc.getCurrentHp() + this._drainHp);
				this._pc.setCurrentHp(newHp);
			}
			// opqlo 硬皮怪 不壞刀 damageNpcWeaponDurability(); // 武器を損傷させる。
			this._targetNpc.receiveDamage(this._pc,Math.min(this._targetNpc.getCurrentHp(), this._damage));
			if (!this._pc.isGm()) {
				return;
			}
		}
		final String srcatk = this._pc.getName();// 攻擊者
		String tgatk = "";// 被攻擊者
		String hitinfo = "";// 資訊
		String dmginfo = "";// 傷害
		String x = "";// 最終資訊

		switch (this._calcType) {
		case PC_PC:
			tgatk = this._targetPc.getName();
			hitinfo = " 命中:" + this._hitRate + "% 剩餘hp:"
					+ this._targetPc.getCurrentHp();
			dmginfo = this._isHit ? "傷害:" + this._damage : "失敗";
			x = srcatk + ">" + tgatk + " " + dmginfo + hitinfo;
			if (this._pc.isGm()) {
				// 166 \f1%0%s %4%1%3 %2。
				this._pc.sendPackets(new S_ServerMessage(166, "對PC送出攻擊: " + x));
			}

			if (this._targetPc.isGm()) {
				// 166 \f1%0%s %4%1%3 %2。
				this._targetPc.sendPackets(new S_ServerMessage(166, "受到PC攻擊: "+ x));
			}
			break;

		case PC_NPC:
			tgatk = this._targetNpc.getName();
			hitinfo = " 命中:" + this._hitRate + "% 剩餘hp:"
					+ this._targetNpc.getCurrentHp();
			dmginfo = this._isHit ? "傷害:" + this._damage : "失敗";
			x = srcatk + ">" + tgatk + " " + dmginfo + hitinfo;
			if (this._pc.isGm()) {
				// 166 \f1%0%s %4%1%3 %2。
				this._pc.sendPackets(new S_ServerMessage(166, "對NPC送出攻擊: " + x));
			}
			break;
		}
	}

	/**
	 * 反擊屏障的傷害反擊
	 */
	@Override
	public void commitCounterBarrier() {
		final int damage = this.calcCounterBarrierDamage();
		if (damage <= 0) {
			return;
		}
		if (this._calcType == PC_PC) {
			this._pc.receiveDamage(this._targetPc, damage, false);
		} else if (this._calcType == PC_NPC) {
			this._targetPc.receiveDamage(this._npc, damage, false);
		} else if (this._calcType == NPC_PC) {
			this._npc.receiveDamage(this._targetPc, damage);

		}
	}

	/**
	 * 技能對武器追加傷害
	 *
	 * @return
	 */
	private double dmgUp() {
		double dmg = 0.0;

		if (this._pc.getSkillEffect().size() <= 0) {
			return dmg;
		}
		if (!this._pc.getSkillisEmpty()) {
			try {
				HashMap<Integer, Integer> skills = null;
				switch (this._weaponType) {
				case 20:// 弓
				case 62:// 鐵手甲
					skills = L1AttackList.SKD2;
					break;

				case 24:// 鎖鍊劍
				default:
					skills = L1AttackList.SKD1;
					break;
				}

				if (skills != null) {
					Integer integer = null;
					for (final Integer key : this._pc.getSkillEffect()) {
						integer = L1AttackList.SKD2.get(key);
						if (integer != null) {
							dmg += integer;
						}
					}
				}

			} catch (final ConcurrentModificationException e) {
				// 技能取回發生其他線程進行修改
			} catch (final Exception e) {
				// _log.error(e.getLocalizedMessage(), e);
			}
		}
		// dmg += _pc.dmgAdd();
		return dmg;
	}

	/**
	 * 攻擊使用武器是否為近距離武器判斷
	 */
	@Override
	public boolean isShortDistance() {
		boolean isShortDistance = true;
		if (this._weaponType == 20 || this._weaponType == 62
				||this._weaponType == 24) { // 弓かガントレット
			isShortDistance = false;
		}
		return isShortDistance;
	}

	private int str_dex_Hit() {
		int hitRate = 0;
		// 力量命中補正
		final Integer hitStr = L1AttackList.STRH.get(this._pc.getStr() - 1);
		if (hitStr != null) {
			hitRate += hitStr;

		} else {
			hitRate += 19;
		}

		// 敏捷命中補正
		final Integer hitDex = L1AttackList.DEXH.get(this._pc.getDex() - 1);
		if (hitDex != null) {
			hitRate += hitDex;

		} else {
			hitRate += 29;
		}
		return hitRate;
	}

	/**opqlo 束縛之箭**/
	private void freeze_arrow(){
		final int chance = Random.nextInt(100)+1;
		if(chance >=6){
			return;
		}
		if (!L1AttackCancel.haveCancelSkill(this._target)
				&& !this._target.hasSkillEffect(SHOCK_STUN)
				&& !this._target.hasSkillEffect(CURSE_PARALYZE)
				&&!this._target.hasSkillEffect(STATUS_FREEZE)) {
			if (this._target instanceof L1PcInstance) {
				this._targetPc.sendPackets(new S_Paralysis(S_Paralysis.TYPE_BIND, true));
				this._targetPc.sendPacketsX8(new S_SkillSound(this._targetPc.getId(), 4184));
			} else if (this._target instanceof L1NpcInstance) {
				// 刪除npc.setParalyzed(false);//opqlo
				// 修正束縛術對怪物暈眩
				this._targetNpc.setPassispeed(0); // opqlo 新增此行
				this._targetNpc.broadcastPacketAll(new S_SkillSound(this._targetNpc.getId(), 4184));
			}
			_target.setSkillEffect(STATUS_FREEZE, 3000);
		}
	}
}
